﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Zor_DAL;
using Zor_Modes;
using Zor_Tools;

namespace Zor_Bll
{

    /// <summary>
    /// 单元信息
    ///  create by Guoph at 2017.3.24
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class Zor_UnitInformation_Bll<T> where T : class 
    {
        /// <summary>
        /// 获取单元信息列表
        /// </summary>
        /// <param name="index">页码</param>
        /// <param name="TotalCount">返回值</param>
        /// <returns></returns>
        public static List<T> GetPageList(int index, out int TotalCount,string where)
        {
           // var sql = where + " order by BD_Id ";

            return PagerHelp<T>.GetPagerList(index, "V_Zor_UnitInformation", "Uim_CreateDate desc ", out TotalCount, where);
        }

        /// <summary>
        /// 获取下拉楼宇列表
        /// </summary>
        /// <returns></returns>
        public static List<T> GetListBuilding()
        {
            return Zor_Building_DAL<T>.GetBuildingList();
        }

        

        /// <summary>
        /// 单元信息-修改
        /// </summary>
        /// <param name="unitInformation">单元信息对象</param>
        /// <returns></returns>
        public static BaseAnswer UpdateUnitInformation(Zor_UnitInfor unitInformation)
        {
            BaseAnswer bar = Zor_UnitInformation_DAL<T>.UpdateUnitInformation(unitInformation);
            if (bar.AnswerType != BaseAnswer.Answers.Error)
                bar.AnswerMeg = bar.AnswerType == BaseAnswer.Answers.Succee ? "修改成功！" : "修改失败，请检查单元信息是否重复！";
            return bar;
        }
        /// <summary>
        /// 单元信息-添加
        /// </summary>
        /// <param name="unitInformation">单元信息对象</param>
        /// <returns></returns>
        public static BaseAnswer InsertUnitInformation(Zor_UnitInfor unitInformation,int flage)
        {
            unitInformation.Uim_CreateDate = TimeHelper.ToNowTimeStamp();
            unitInformation.User_Id = RequestSession.GetSessionUser().User_Id;
            unitInformation.Uim_Flage = flage;
            BaseAnswer bar = Zor_UnitInformation_DAL<T>.InsertUnitInformation(unitInformation);
            if (bar.AnswerType != BaseAnswer.Answers.Error)
                bar.AnswerMeg = bar.AnswerType == BaseAnswer.Answers.Succee ? "增加成功！" : "新增失败，请检查单元信息是否重复！";
            return bar;
        }
       /// <summary>
       /// 单元信息-删除
       /// </summary>
       /// <param name="id">单元信息ID</param>
       /// <returns></returns>
        public static BaseAnswer DeleteUnitInformation(int[] id)
        {
            BaseAnswer bar = Zor_UnitInformation_DAL<T>.DeleteUnitInformation(id);
            if (bar.AnswerType != BaseAnswer.Answers.Error)
                bar.AnswerMeg = bar.AnswerType == BaseAnswer.Answers.Succee ? "删除成功！" : "删除失败！";
            return bar;
        }
        /// <summary>
        /// 获取单元信息列表（不分页）
        /// create 刘云飞 by 2017/04/06       
        /// </summary>
        /// <returns></returns>
        public static List<T> GetList(string where)
        {
            return Zor_UnitInformation_DAL<T>.SelectViewInformation(where);
        }
        /// <summary>
        /// 获取门牌信息列表（不分页）
        /// </summary>
        /// <returns></returns>
        public static List<T> GetDoorpList(dynamic model, string where)
        {
            var sqlSurch = string.Empty;
            if (model.Bd_Name != null)
            {
                sqlSurch += " Bd_Name like '%" + model.Bd_Name + "%' and ";
            }
            if (model.Uim_Name != null)
            {
                sqlSurch += " Uim_Name like '%" + model.Uim_Name + "%' and ";
            }
            sqlSurch += " Uim_Flage = 1";
            return Zor_UnitInformation_DAL<T>.SelectViewDoorpInformation(sqlSurch);
        }
        /// <summary>
        /// 获取所属街道名称
        /// </summary>
        /// <returns></returns>
        public static List<T> GetBdName()
        {
            return Zor_UnitInformation_DAL<T>.GetBdName();
        }



    }
    
}
